package models;

import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import com.hp.hpl.jena.rdf.model.Resource;


public class PropertyModel implements Comparable<PropertyModel>
{
    public Resource                     property;       // uri
    // language ->
    public Map<String, HashSet<String>> values;         // key = language
    public Set<String>               linkedInstances;


    public PropertyModel(Resource property)
    {
        this.property = property;
        values = new LinkedHashMap<String, HashSet<String>>();
        linkedInstances = new HashSet<>();
    }


    public void addValue(String language, String value)
    {
        if(!values.containsKey(language)) {
            values.put(language, new HashSet<String>());
        }

        values.get(language).add(value);
    }


    public void setValues(Map<String, HashSet<String>> values)
    {
        this.values = values;
    }


    public Map<String, HashSet<String>> getValues()
    {
        return values;
    }


    public Set<String> getValuesByLanguage(String lang)
    {
        if(values.containsKey(lang)) { return values.get(lang); }

        return new HashSet<String>();
    }


    public Set<String> getValuesByDefault()
    {
        if(values.containsKey("en")) { return values.get("en"); }
        if(values.containsKey("XX")) { return values.get("XX"); }
        return new HashSet<String>();
    }


    public Set<String> getLanguages()
    {
        return values.keySet();
    }


    public int getSize()
    {
        return values.size();
    }


    public String getURI()
    {
        return property.getURI();
    }


    @Override
    public int compareTo(PropertyModel p)
    {
        return this.property.getURI().compareTo(p.property.getURI());
    }


    @Override
    public String toString()
    {
        String s = property.getURI();
        s += " [";
        for(String temp : values.keySet()) {
            s += " " + values.get(temp) + "(" + temp + ")";
        }
        s += "]";
        return s;
    }
}